package com.zhongwang.mms.module.allocation.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.User;
import com.zhongwang.mms.module.allocation.model.AllocationOrderModel;
import com.zhongwang.mms.module.allocation.service.AllocationOrderService;
import com.zhongwang.mms.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @description:调拨查询
 * @author: th
 * @time: 2020/8/21 10:18
 */
@Controller
@RequestMapping("/allocationQuery")
public class AllocationQueryController extends BaseController {

    //页面文件路径
    private String prefix = "allocation/allocationQuery";
    @Autowired
    private AllocationOrderService allocationOrderService;

    //加载页面
    @GetMapping("/page")
    @RequiresPermissions({"allocation:query:view"})
    public String create(Model model) {

        // 获取登入用户实体
        User user = ShiroUtils.getUser();
        model.addAttribute("userName", user.getName());
        model.addAttribute("odrDate", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        return prefix + "/page";    }

    /**
     *  调拨查询页面数据
     * @param query
     * @return
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"allocation:query:view"})
    public JsonResult list(AllocationOrderModel query){

        startPage();
        List<AllocationOrderModel> list = allocationOrderService.selectOrderDetailByQuery(query);
        return jsonResult(list);
    }
}
